/**
 * 获取图片信息
 * @param {string} imgObj 图片对象path
 * @param {function} fn 回调函数
 * @returns {ojbect} cbParams 
 * {
 *  height: 722,
 *  width: 1366,
 *  type: 'png',
 *  path: '',
 *  orientation: 'up',
 *  errMsg: ''
 * }
 */
function getImageObject(src, fn) {
	uni.getImageInfo({
		src: src,
		success(res) {
			fn(res)
		}
	})
}

/**
 * 压缩图片
 * @param {object} img 图片
 * @param {function} fn 回调函数
 */
function compressImg(img, fn) {
	const selectorQuery = uni.createSelectorQuery()
	selectorQuery.select('#canvas')
		.fields({ node: true, size: true })
		.exec(res => {
			const canvas = res[0].node
			const ctx = canvas.getContext('2d')
			canvas.height = img.height
			canvas.width = img.width

			let seal = canvas.createImage()
			seal.src = img.path
			seal.onload = () => {
				ctx.drawImage(seal, 0, 0, img.width, img.height)
				const url = canvas.toDataURL('image/jpeg', .1)
				fn(url)
			}
		})
}
